package com.lesama.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

// 网络通信： UDP

public class Sender {
    public static void main(String[] args) throws IOException {
        // 1. 创建DatagramSocket对象
        DatagramSocket datagramSocket = new DatagramSocket(8888);
        // 2. 创建DatagramPacket对象
        String msg = "summer pockets";
        byte[] bytes = msg.getBytes();
        DatagramPacket datagramPacket = new DatagramPacket(bytes, bytes.length, InetAddress.getByName("127.0.0.1"), 9999);
        // 3. 发送消息
        datagramSocket.send(datagramPacket);
        // 4. 关闭datagramSocket
        datagramSocket.close();
    }
}
